package tree;

/**
 * @ClassName ReverseTreeNode
 * @Description TODO
 * @Author lenovo
 * @Date 2023-03-08 11:33
 * @Version 1.0
 * @Comment Magic. Do not touch.
 * If this comment is removed. the program will blow up
 */
public class ReverseTreeNode {

    /**
     * 翻转二叉树
     *
     * @param root
     * @return
     */
    public TreeNode reverseTreeNode(TreeNode root) {
        if (root == null) return null;
        int val =root.val;
        reverseTreeNode(root.left);
        reverseTreeNode(root.right);

        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        return root;
    }

    public static void main(String[] args) {
        ReverseTreeNode reverseTreeNode = new ReverseTreeNode();

        TreeNode treeNode = new TreeNode(2);

        TreeNode treeNodeLeft = new TreeNode(1);
        treeNode.left = treeNodeLeft;

        TreeNode treeNodeRight = new TreeNode(3);
        treeNode.right = treeNodeRight;

        TreeNode treeNode1 = reverseTreeNode.reverseTreeNode(treeNode);
        System.out.println(treeNode1.toString());
    }
}